package com.ylxl.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylxl.common.annotation.Log;
import com.ylxl.common.enums.BusinessType;
import com.ylxl.common.result.AjaxResult;
import com.ylxl.common.result.BaseController;
import com.ylxl.common.utils.StringUtils;
import com.ylxl.entity.Device;
import com.ylxl.entity.reponse.ContainerVO;
import com.ylxl.entity.request.QueryContainer;
import com.ylxl.entity.request.QueryDevice;
import com.ylxl.service.IContainerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备管理
 * @Auther Gilbert
 * @Date 2023/6/26 15:10
 */
@Slf4j
@RestController
@RequestMapping("/device")
@Api(tags = "设备管理", hidden = true)
public class DeviceController extends BaseController {
    @Resource
    private IContainerService containerService;
    /**
     * 分页查询设备列表信息
     * @param queryDevice
     * @return
     */
    @Log(title = "分页查询设备列表信息", businessType = BusinessType.SELECT)
    @PostMapping("/queryDeviceList")
    @ApiOperation(value = "分页查询设备列表信息", response = AjaxResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Device.class),})
    public AjaxResult queryDeviceList(@RequestBody QueryDevice queryDevice) {
        AjaxResult ajax = AjaxResult.success();
        try {
            //进行分页操作
            PageInfo<Device> pageInfo = new PageInfo<>();
            if (StringUtils.isNotEmpty(queryDevice.getPageNum()) && StringUtils.isNotEmpty(queryDevice.getPageSize())) {
                PageHelper.startPage(queryDevice.getPageNum(), queryDevice.getPageSize());
            }
            List<Device> devices = containerService.selectDeviceList(queryDevice);
            pageInfo = new PageInfo<>(devices);
            ajax.put(AjaxResult.DATA_TAG, devices);
            ajax.put(AjaxResult.TOTAL, pageInfo.getTotal());
        } catch (Exception e) {
            log.error("查询设备列表日志信息，异常信息：{}", e);
            return toAjax(false);
        }
        return ajax;
    }
}
